package com.lhy.admin.common.mvcplus.java8time;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDateTime;

/**
 * 时间参数接收转换器，将字符串转为时间类型
 */
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {

    @Override
    public LocalDateTime convert(String s) {
        if (StrUtil.isEmpty(s)) {
            return null;
        }
        return LocalDateTimeUtil.parse(s, DatePattern.NORM_DATETIME_PATTERN);
    }
}
